package org.workstream.data;

import java.util.HashMap;

import net.sourceforge.sizeof.SizeOf;

public class DataSizeHelper {
	private static HashMap<Class<?>,Long> classSizeMap = new HashMap<Class<?>,Long>();
	
	public static long GetObjSize(Object obj){
		Class<?> runTimeClass = obj.getClass();
		synchronized(classSizeMap){
			if(classSizeMap.get(runTimeClass) == null){
				SizeOf.skipStaticField(true);
				SizeOf.setMinSizeToLog(10);
				SizeOf.turnOffDebug();
				long size = SizeOf.sizeOf(obj);
				classSizeMap.put(runTimeClass, size);
				return size;
			}
			else
				return classSizeMap.get(runTimeClass);
		}
	}
}
